package com.seaboxdata.scheduler;

import com.seaboxdata.entity.OldStrategyConfig;
import com.seaboxdata.service.HdfsDataAgeService;
import com.seaboxdata.service.HiveDataAgeService;
import com.seaboxdata.service.MysqlDataAgeService;
import com.seaboxdata.service.OldStrategyConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Configuration
@Slf4j
public class DataAgeJob {

    @Autowired
    private OldStrategyConfigService oldStrategyConfigService;

    @Autowired
    private HiveDataAgeService hiveDataAgeService;

    @Autowired
    private HdfsDataAgeService hdfsDataAgeService;

    @Autowired
    private MysqlDataAgeService mysqlDataAgeService;

    @Scheduled(cron = "${data.age.interver}")
    public void doCollect() {
        List<OldStrategyConfig> allEffectiveConfigs = oldStrategyConfigService.getAllEffectiveConfigs();
        //判断是什么数据类型的,分为，hive，hdfs，mysql，system
        for (OldStrategyConfig allEffectiveConfig : allEffectiveConfigs) {
            switch (allEffectiveConfig.getDataType()) {
                case "hive": {
                    //hive删除数据，删除分区，
                    hiveDataAgeService.dataAge(allEffectiveConfig);
                    break;
                }
                case "hdfs": {
                    //hdfs删除指定数据
                    hdfsDataAgeService.dataAge(allEffectiveConfig);
                    break;
                }
                case "mysql": {
                    //mysql删除最近数据
                    mysqlDataAgeService.dataAge(allEffectiveConfig);
                    break;
                }
                case "system": {
                    //删除系统数据
                    break;
                }
                default: {
                    log.error("not support this dataType data age,dataType:" + allEffectiveConfig.getDataType());
                    break;
                }
            }
        }
    }
}
